import { defineStore } from 'pinia'
import { store } from '/@/store'
import type { AxiosResponse } from 'axios'
import type { Res } from '/@/tool/Res'
import type { Param } from '/@/tool/Param'
import type { DataExportAO } from '/@/model/cn/core/tool/ao/DataExportAO'

import taskParamService from '/@/api/cn/core/kpis/taskParamService'

import type { TaskParam } from '/@/model/cn/core/kpis/eo/TaskParam'
import type { TaskParamQO } from '/@/model/cn/core/kpis/qo/TaskParamQO'
import type { TaskParamVO } from '/@/model/cn/core/kpis/vo/TaskParamVO'

interface TaskParamState {
}

export const useTaskParamStore = defineStore({
  id: 'taskParam',
  state: (): TaskParamState => ({
  }),
  getters: {
  },
  actions: {
    save(param: Param<TaskParam>): Promise<Res<TaskParam>> {
      return new Promise<Res<TaskParam>>((resolve, reject) => {
        taskParamService.save(param).then((res: AxiosResponse<Res<TaskParam>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    saveBatch(param: Param<TaskParam>): Promise<Res<TaskParam>> {
      return new Promise<Res<TaskParam>>((resolve, reject) => {
        taskParamService.saveBatch(param).then((res: AxiosResponse<Res<TaskParam>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    update(param: Param<TaskParam>): Promise<Res<TaskParam>> {
      return new Promise<Res<TaskParam>>((resolve, reject) => {
        taskParamService.update(param).then((res: AxiosResponse<Res<TaskParam>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    updateBatch(param: Param<TaskParam>): Promise<Res<TaskParam>> {
      return new Promise<Res<TaskParam>>((resolve, reject) => {
        taskParamService.updateBatch(param).then((res: AxiosResponse<Res<TaskParam>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    remove(param: Param<TaskParam>): Promise<Res<TaskParam>> {
      return new Promise<Res<TaskParam>>((resolve, reject) => {
        taskParamService.remove(param).then((res: AxiosResponse<Res<TaskParam>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    removeBatch(param: Param<TaskParam>): Promise<Res<TaskParam>> {
      return new Promise<Res<TaskParam>>((resolve, reject) => {
        taskParamService.removeBatch(param).then((res: AxiosResponse<Res<TaskParam>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    count(param: Param<TaskParamQO>): Promise<Res<TaskParam>> {
      return new Promise<Res<TaskParam>>((resolve, reject) => {
        taskParamService.count(param).then((res: AxiosResponse<Res<TaskParam>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    pk(param: Param<TaskParamQO>): Promise<Res<TaskParam>> {
      return new Promise<Res<TaskParam>>((resolve, reject) => {
        taskParamService.pk(param).then((res: AxiosResponse<Res<TaskParam>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    query(param: Param<TaskParamQO>): Promise<Res<TaskParam>> {
      return new Promise<Res<TaskParam>>((resolve, reject) => {
        taskParamService.query(param).then((res: AxiosResponse<Res<TaskParam>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    paging(param: Param<TaskParamQO>): Promise<Res<TaskParam>> {
      return new Promise<Res<TaskParam>>((resolve, reject) => {
        taskParamService.paging(param).then((res: AxiosResponse<Res<TaskParam>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    countVo(param: Param<TaskParamQO>): Promise<Res<TaskParamVO>> {
      return new Promise<Res<TaskParamVO>>((resolve, reject) => {
        taskParamService.countVo(param).then((res: AxiosResponse<Res<TaskParamVO>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    pkVo(param: Param<TaskParamQO>): Promise<Res<TaskParamVO>> {
      return new Promise<Res<TaskParamVO>>((resolve, reject) => {
        taskParamService.pkVo(param).then((res: AxiosResponse<Res<TaskParamVO>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    queryVo(param: Param<TaskParamQO>): Promise<Res<TaskParamVO>> {
      return new Promise<Res<TaskParamVO>>((resolve, reject) => {
        taskParamService.queryVo(param).then((res: AxiosResponse<Res<TaskParamVO>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    pagingVo(param: Param<TaskParamQO>): Promise<Res<TaskParamVO>> {
      return new Promise<Res<TaskParamVO>>((resolve, reject) => {
        taskParamService.pagingVo(param).then((res: AxiosResponse<Res<TaskParamVO>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    dataImport(param: Param<string>): Promise<Res<TaskParam>> {
      return new Promise<Res<TaskParam>>((resolve, reject) => {
        taskParamService.dataImport(param).then((res: AxiosResponse<Res<TaskParam>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    dataExport(param: Param<DataExportAO<TaskParamQO>>): Promise<Res<string>> {
      return new Promise<Res<string>>((resolve, reject) => {
        taskParamService.dataExport(param).then((res: AxiosResponse<Res<string>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
  },
})

export function useTaskParamStoreWithout() {
  return useTaskParamStore(store)
}
